Fix CommandRunnerTask options handling - #187
Tmalboeuf-CA wants to merge 1 commit into
Conversation
|
Hello @Tmalboeuf-CA , could you provide a simple example of not working code ? |
|
@njoubert-cleverage clever_age_process:
configurations:
demo.command_runner:
tasks:
run:
service: '@CleverAge\ProcessBundle\Task\Process\CommandRunnerTask'
options:
commandline: ['echo', 'hello']
outputs: [debug]
debug:
service: '@CleverAge\ProcessBundle\Task\Debug\DebugTask'The whole resolved options array ( A string options:
commandline: 'echo hello'With this PR, both processes output |
The whole task options array was passed to Process::setOptions(), which only accepts blocking_pipes, create_process_group and create_new_console: every execution failed with 'Invalid option "cwd"'. A string commandline, although allowed, also failed with a TypeError. - Pass only the `options` option to Process::setOptions() - Run string commandlines through Process::fromShellCommandline() - Validate cwd, env, timeout and options types - Update the reference documentation, add unit tests Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
98916e8 to
28a48db
Compare
Description
CommandRunnerTaskcould not be used at all: every execution failed.Process::setOptions(). That method only acceptsblocking_pipes,create_process_groupandcreate_new_console, so every run threwLogicException: Invalid option "cwd" passed to "Symfony\Component\Process\Process::setOptions()".commandlineis allowed by the options resolver, butnew Process()only accepts an array. It threw aTypeError.This PR:
optionsoption toProcess::setOptions(), and only when it is set;Process::fromShellCommandline(), so pipes and environment variables work ('grep "$PATTERN" | wc -l');cwd(null|string),env(null|array),timeout(null|int|float) andoptions(null|array), so a wrong value is reported when options are resolved instead of failing inside Symfony Process;docs/reference/tasks/command_runner_task.md) and links it fromdocs/index.md.Tested with 7 new unit tests (array and string commandlines, stdin input,
cwd/env, process options, invalid option type, failing command). They all fail onmainand pass with this fix. The full suite, PHPStan and PHP-CS-Fixer pass. Also checked end to end in a Symfony 7.4 app.Requirements
Breaking changes
None. Every configuration of this task failed before this change, so no working setup can break. The new type validation only rejects values that already crashed.